package com.yanqu.road.dao.impl.activity.seacraft;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.seacraft.pirateriot.config.SeacraftPirateRiotMonsterConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SeacraftPirateRiotMonsterConfigDaoImpl extends TempDao {

    private static String getSeacraftPirateRiotMonsterConfigSql = "select * from `t_s_activity_seacraft_monster` where `activityId`=?";

    public Map<Integer, SeacraftPirateRiotMonsterConfig> getSeacraftPirateRiotMonsterConfigMap(int activityId) {
        Map<Integer, SeacraftPirateRiotMonsterConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSeacraftPirateRiotMonsterConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SeacraftPirateRiotMonsterConfig seacraftPirateRiotMonsterConfig = new SeacraftPirateRiotMonsterConfig();
                seacraftPirateRiotMonsterConfig.setActivityId(rs.getInt("activityId"));
                seacraftPirateRiotMonsterConfig.setMonsterId(rs.getInt("monsterId"));
                seacraftPirateRiotMonsterConfig.setQuality(rs.getInt("quality"));
                seacraftPirateRiotMonsterConfig.setFirstReward(rs.getString("firstReward"));
                seacraftPirateRiotMonsterConfig.setSeaId(rs.getString("seaId"));
                seacraftPirateRiotMonsterConfig.setHealth(rs.getInt("health"));
                seacraftPirateRiotMonsterConfig.setAttack(rs.getInt("attack"));
                seacraftPirateRiotMonsterConfig.setAttackCd(rs.getInt("attackCd"));
                seacraftPirateRiotMonsterConfig.setAnger(rs.getInt("anger"));
                map.put(seacraftPirateRiotMonsterConfig.getMonsterId(), seacraftPirateRiotMonsterConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
